package com.example.adminui.controller;

import com.example.adminui.entity.Lead;
import com.example.adminui.service.LeadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/api/leads")
public class LeadController {
    @Autowired
    private LeadService leadService;

    @GetMapping
    public List<Lead> getAllLeads() {
        return leadService.getAllLeads();
    }

    @GetMapping("/{id}")
    public Lead getLeadById(@PathVariable Long id) {
        return leadService.getLeadById(id);
    }

    @PostMapping
    public void createLead(@RequestBody Lead lead) {
        leadService.createLead(lead);
    }

    @PutMapping("/{id}")
    public void updateLead(@PathVariable Long id, @RequestBody Lead lead) {
        lead.setId(id);
        leadService.updateLead(lead);
    }

    @DeleteMapping("/{id}")
    public void deleteLead(@PathVariable Long id) {
        leadService.deleteLead(id);
    }
}